const express = require('express');
const mysql = require('mysql2/promise');
const cors = require('cors');

const app = express();
app.use(cors()); // 允许跨域请求

// API endpoint to get the total count of parking records
app.get('/api/parking-count', async (req, res) => {
    try {
        const [rows] = await pool.query('SELECT COUNT(*) AS total FROM a_parking_data');
        const totalCount = rows[0].total;
        res.json({ title: '停车数量', value: totalCount });
    } catch (err) {
        console.error(err);
        res.status(500).send('Server Error');
    }
});

// 启动服务器
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));